package com.tkjt.pms.modules.kpiAudit.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.jeecg.common.system.vo.LoginUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.tkjt.pms.common.utils.EsStringUtils;
import com.tkjt.pms.modules.common.service.TkDataConfigService;
import com.tkjt.pms.modules.kpiAudit.model.kpiAuditrowList.KpiAuditrowListModel;
import com.tkjt.pms.modules.kpiAudit.model.vo.AuditStatisticsVO;
import com.tkjt.pms.modules.kpiAudit.service.KpiAuditBizService;
import com.tkjt.pms.modules.kpiAudit.service.KpiAuditService;

@Transactional
@Service
public class KpiAuditServiceImpl implements KpiAuditService {
    @Autowired
    private TkDataConfigService tkDataConfigService;

    @Autowired
    private Map<String, KpiAuditBizService> kpiAuditBizServiceMap = new HashMap<>();

    @Override
    public KpiAuditrowListModel getKpiAuditrowListModel(LoginUser loginUser, HttpServletRequest request) {
        String dataType = tkDataConfigService.getDataType(loginUser.getUsername());
        KpiAuditBizService kpiAuditBizService = checkService(dataType);
        return kpiAuditBizService.getKpiAuditrowListModel(request, dataType);
    }

    @Override
    public List<AuditStatisticsVO> getAuditStatisticsVOList(LoginUser loginUser, HttpServletRequest request) {
        String dataType = tkDataConfigService.getDataType(loginUser.getUsername());
        KpiAuditBizService kpiAuditBizService = checkService(dataType);
        return kpiAuditBizService.getAuditStatisticsVOList(request, dataType);
    }

    @Override
    public String toSubmitAudit(LoginUser loginUser, HttpServletRequest request) {
        String dataType = tkDataConfigService.getDataType(loginUser.getUsername());
        KpiAuditBizService kpiAuditBizService = checkService(dataType);
        return kpiAuditBizService.toSubmitAudit(request, dataType);
    }

    public KpiAuditBizService checkService(String dataType) {
        String serviceName = "kpiAuditBizService" + EsStringUtils.onlyFirstCharUpper(dataType);
        return kpiAuditBizServiceMap.get(serviceName);
    }
}
